<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <link href="css/base.css" rel="stylesheet">
    <link href="css/head.css" rel="stylesheet">
    <link href="css/login.css" rel="stylesheet">
</head>

<body>
    <script src="js/jquery-3.6.0.min.js"></script>
    <script src="js/head.js"></script>
    <script src="js/upload.js"></script>
    <script src="js/Utils.js"></script>


    <div class="head"></div>
    <div class="main">
        <div class="login">
            <h3>管理员登陆</h3>
        </div>

        <div class="form">
            <input type="text" name="username" placeholder="用户名" id="username">
            <input type="password" placeholder="密码" id="password">
        </div>

        <div style="width: 50%;">
            <div class="button" id="login">
                登陆
            </div>
        </div>
    </div>

    <script>


        $('document').ready(function () {
            // if(hasLogin())
            //     location.href="mine.html"

            $('#login').click(function () {
                let username = $('#username').val()
                let password = $('#password').val()

                if (username == "" || password == "") {

                    alert("请填写用户名或密码")
                    return
                }

                let data = {
                        username,
                        password
                    }
                
                data = JSON.stringify(data)

                $.ajax({
                    data,
                    url: baseUrl + 'admin/login.php',
                    type: 'POST',
                    success: function (res) {
                        if(typeof(res) == 'string')
                            res = JSON.parse(res)

                        if(res.code == 200){
                            setSession('admin', res.data)
                            location.href = 'mine.html'
                        }else
                            alert(res.msg)
                    }
                })
            })
        })
    </script>
</body>

</html>